package edu.suda.xsap.service.impl;

import edu.suda.xsap.dto.CourseDto;
import edu.suda.xsap.dto.EmployeeDto;
import edu.suda.xsap.dto.convert.CourseConvert;
import edu.suda.xsap.entity.Course;
import edu.suda.xsap.entity.ReservationSet;
import edu.suda.xsap.entity.vo.ClassRecordVo;
import edu.suda.xsap.entity.vo.ReservationVo;
import edu.suda.xsap.mapper.CourseMapper;
import edu.suda.xsap.mapper.ReservationSetMapper;
import edu.suda.xsap.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseConvert courseConvert;

    @Autowired
    private CourseMapper courseMapper;
    @Autowired
    private ReservationSetMapper reservationSetMapper;
    @Override
    public void save(Course course) {courseMapper.save(course);
    }

    @Override
    public void delete(Integer id) {
        courseMapper.delete(id);
    }

    @Override
    public void update(Course course) {
        courseMapper.update(course);
    }

    @Override
    public CourseDto findById(Integer id) {
        Course course = courseMapper.findById(id);
        return courseConvert.toDto(course);
    }

    @Override
    public CourseDto findByName(String name) {
        Course course = courseMapper.findByName(name);
        return courseConvert.toDto(course);
    }

    @Override
    public List<CourseDto> findAll() {
        List<Course> courses = courseMapper.findAll();
        return courseConvert.toDtoList(courses);

    }

    @Override
    public List<ReservationVo> find(Integer id) {
        return courseMapper.find(id);
    }

    @Override
    public List<ClassRecordVo> findClassRecord(Integer id) {
        return courseMapper.findClassRecord(id);
    }

    @Override
    public void saveReservation(ReservationSet reservation) {
        reservation.setCreateTime(LocalDateTime.now());
        reservationSetMapper.save(reservation);
    }

    @Override
    public Integer findCount() {
        return courseMapper.findCount();
    }

    @Override
    public List<CourseDto> findByLimit(int i, int i1) {
        return courseConvert.toDtoList(courseMapper.findByLimit(i,i1));
    }
}
